home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / DUMP.C < prev    next >
C/C++ Source or Header  |  1992-02-03  |  7KB  |  227 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/dump.c,v 9.35 1992/02/03 23:25:45 jinx Exp $
  4.  
  5. Copyright (c) 1987-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* This file contains common code for dumping internal format binary files. */
  36.  
  37. extern SCHEME_OBJECT compiler_utilities;
  38. extern long compiler_interface_version, compiler_processor_type;
  39.  
  40. void
  41. DEFUN (prepare_dump_header,
  42.        (Buffer, Dumped_Object,
  43.     Heap_Count, Heap_Relocation,
  44.     Constant_Count, Constant_Relocation,
  45.     table_length, table_size,
  46.     cc_code_p, band_p),
  47.        SCHEME_OBJECT *Buffer AND
  48.        SCHEME_OBJECT *Dumped_Object AND
  49.        long Heap_Count AND
  50.        SCHEME_OBJECT *Heap_Relocation AND
  51.        long Constant_Count AND
  52.        SCHEME_OBJECT *Constant_Relocation AND
  53.        long table_length AND
  54.        long table_size AND
  55.        Boolean cc_code_p AND
  56.        Boolean band_p)
  57. {
  58.   long i;
  59.  
  60. #ifdef DEBUG
  61.  
  62. #ifndef HEAP_IN_LOW_MEMORY
  63.   fprintf(stderr, "\nmemory_base = 0x%lx\n", ((long) memory_base));
  64. #endif /* HEAP_IN_LOW_MEMORY */
  65.  
  66.   fprintf(stderr, "\nHeap_Relocation=0x%lx, dumped as 0x%lx\n",
  67.       ((long) Heap_Relocation),
  68.       ((long) (MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Heap_Relocation))));
  69.   fprintf(stderr, "\nDumped object=0x%lx, dumped as 0x%lx\n",
  70.       ((long) Dumped_Object),
  71.       ((long) (MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Dumped_Object))));
  72. #endif /* DEBUG */
  73.  
  74.   Buffer[FASL_Offset_Marker] = FASL_FILE_MARKER;
  75.   Buffer[FASL_Offset_Heap_Count] =
  76.     MAKE_OBJECT (TC_BROKEN_HEART, Heap_Count);
  77.   Buffer[FASL_Offset_Heap_Base] =
  78.     MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Heap_Relocation);
  79.   Buffer[FASL_Offset_Dumped_Obj] =
  80.     MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Dumped_Object);
  81.   Buffer[FASL_Offset_Const_Count] =
  82.     MAKE_OBJECT (TC_BROKEN_HEART, Constant_Count);
  83.   Buffer[FASL_Offset_Const_Base] =
  84.     MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Constant_Relocation);
  85.   Buffer[FASL_Offset_Version] =
  86.     Make_Version(FASL_FORMAT_VERSION,
  87.          FASL_SUBVERSION, FASL_INTERNAL_FORMAT);
  88.   Buffer[FASL_Offset_Stack_Top] =
  89. #ifdef USE_STACKLETS
  90.     MAKE_OBJECT (TC_BROKEN_HEART, 0);    /* Nothing in stack area */
  91. #else
  92.     MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Stack_Top);
  93. #endif /* USE_STACKLETS */
  94.  
  95.   Buffer[FASL_Offset_Prim_Length] =
  96.     MAKE_OBJECT (TC_BROKEN_HEART, table_length);
  97.   Buffer[FASL_Offset_Prim_Size] =
  98.     MAKE_OBJECT (TC_BROKEN_HEART, table_size);
  99.  
  100.   if (cc_code_p)
  101.   {
  102.     Buffer[FASL_Offset_Ci_Version] =
  103.       MAKE_CI_VERSION(band_p,
  104.               compiler_interface_version,
  105.               compiler_processor_type);
  106.     Buffer[FASL_Offset_Ut_Base] = compiler_utilities;
  107.   }
  108.   else
  109.   {
  110.     /* If there is no compiled code in the file,
  111.        flag it as if dumped without compiler support, so
  112.        it can be loaded anywhere.
  113.      */
  114.     Buffer[FASL_Offset_Ci_Version] = MAKE_CI_VERSION(band_p, 0, 0);
  115.     Buffer[FASL_Offset_Ut_Base] = SHARP_F;
  116.   }
  117.  
  118.   Buffer[FASL_Offset_Check_Sum] = SHARP_F;
  119.   for (i = FASL_Offset_First_Free; i < FASL_HEADER_LENGTH; i++)
  120.   {
  121.     Buffer[i] = SHARP_F;
  122.   }
  123.   return;
  124. }
  125.  
  126. extern unsigned long
  127.   EXFUN (checksum_area, (unsigned long *, long, unsigned long));
  128.  
  129. Boolean
  130. DEFUN (Write_File,
  131.        (Dumped_Object, Heap_Count, Heap_Relocation,
  132.     Constant_Count, Constant_Relocation,
  133.     table_start, table_length, table_size,
  134.     cc_code_p, band_p),
  135.        SCHEME_OBJECT *Dumped_Object
  136.        AND long Heap_Count
  137.        AND SCHEME_OBJECT *Heap_Relocation
  138.        AND long Constant_Count
  139.        AND SCHEME_OBJECT *Constant_Relocation
  140.        AND SCHEME_OBJECT *table_start
  141.        AND long table_length
  142.        AND long table_size
  143.        AND Boolean cc_code_p
  144.        AND Boolean band_p)
  145. {
  146.   SCHEME_OBJECT Buffer[FASL_HEADER_LENGTH];
  147.   unsigned long checksum;
  148.  
  149.   prepare_dump_header (Buffer, Dumped_Object,
  150.                Heap_Count, Heap_Relocation,
  151.                Constant_Count, Constant_Relocation,
  152.                table_length, table_size, cc_code_p, band_p);
  153.  
  154.   /* This is not done in prepare_dump_header because it doesn't
  155.      work when prepare_dump_header is invoked from bchdmp.
  156.      The areas don't really have these values.
  157.      For the time being, bchdmp does not dump checksums.
  158.    */
  159.  
  160.   checksum = (checksum_area (((unsigned long *) (&Buffer[0])),
  161.                  ((long) FASL_Offset_Check_Sum),
  162.                  ((unsigned long) 0L)));
  163.   checksum = (checksum_area (((unsigned long *)
  164.                   (&Buffer[FASL_Offset_Check_Sum + 1])),
  165.                  ((long) ((FASL_HEADER_LENGTH - 1) -
  166.                       FASL_Offset_Check_Sum)),
  167.                  checksum));
  168.   checksum = (checksum_area (((unsigned long *) Heap_Relocation),
  169.                  Heap_Count,
  170.                  checksum));
  171.   checksum = (checksum_area (((unsigned long *) Constant_Relocation),
  172.                  Constant_Count,
  173.                  checksum));
  174.   checksum = (checksum_area (((unsigned long *) table_start),
  175.                  table_size,
  176.                  checksum));
  177.   Buffer[FASL_Offset_Check_Sum] = checksum;
  178.  
  179.   if ((Write_Data (FASL_HEADER_LENGTH, Buffer)) !=
  180.       FASL_HEADER_LENGTH)
  181.   {
  182.     return (false);
  183.   }
  184.   if (Heap_Count != 0)
  185.   {
  186.     if ((Write_Data (Heap_Count, Heap_Relocation)) !=
  187.     Heap_Count)
  188.     {
  189.       return (false);
  190.     }
  191.   }
  192.   if (Constant_Count != 0)
  193.   {
  194.     if ((Write_Data (Constant_Count, Constant_Relocation)) !=
  195.     Constant_Count)
  196.     {
  197.       return (false);
  198.     }
  199.   }
  200.   if (table_size != 0)
  201.   {
  202.     if ((Write_Data (table_size, table_start)) !=
  203.     table_size)
  204.     {
  205.       return (false);
  206.     }
  207.   }
  208.   return (true);
  209. }
  210.  
  211. unsigned long
  212. DEFUN (checksum_area, (start, count, initial_value),
  213.        register unsigned long * start
  214.        AND register long count
  215.        AND unsigned long initial_value)
  216. {
  217.   register unsigned long value;
  218.  
  219.   value = initial_value;
  220.   while ((--count) >= 0)
  221.   {
  222.     value = (value ^ (*start++));
  223.   }
  224.   return (value);
  225. }
  226.  
  227.